﻿using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using rpc_service.util;

namespace DynamicProxy
{
    class TestProxy : rpc_service.test.Test
    {
        private Microsoft.Extensions.Logging.ILogger _logger =
            rpc_service.log.Logger.GetLoggerFactory().CreateLogger("TestProxy");

        public async System.Threading.Tasks.Task<System.String> Test1()
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {

                client.DefaultRequestHeaders.Add("dafds", "sdafdasfdsaf");
                client.DefaultRequestHeaders.Add("Authorization",
                    MethodUtil.InvokeMethod("rpc_service.test.Test2.Test1"));
                client.Timeout = TimeSpan.FromSeconds(60);
                System.String url = "http://localhost:5238";
                url = "http://localhost:5238" + "/";
                url = url + "weatherforecast";
                System.Text.StringBuilder urlBuilder = new System.Text.StringBuilder();
                urlBuilder.Append(url + "?");
                urlBuilder.Remove(urlBuilder.Length - 1, 1);
                System.String json = System.Text.Json.JsonSerializer.Serialize("");
                System.Net.Http.StringContent content =
                    new System.Net.Http.StringContent("", System.Text.Encoding.UTF8, "application/json");
                System.Collections.Generic.IDictionary<System.String, System.Object> parameters =
                    new System.Collections.Generic.Dictionary<System.String, System.Object>();
                parameters["client"] = client;
                parameters["url"] = urlBuilder.ToString();
                parameters["data"] = json;
                rpc_service.core.interceptor.impl.RequestInterceptor requestInterceptor =
                    new rpc_service.core.interceptor.impl.RequestInterceptor();
                requestInterceptor.PreInterceptor(parameters);
                try
                {
                    HttpResponseMessage response = await client.GetAsync(urlBuilder.ToString());
                    response.EnsureSuccessStatusCode();
                    System.String responseBody = await response.Content.ReadAsStringAsync();
                    requestInterceptor.PostInterceptor(parameters);
                    return responseBody;
                }
                catch (HttpRequestException e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new HttpRequestException(e.Message);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new Exception(e.Message);
                }
            }
        }

        public System.String Test2(System.Int32 id)
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {

                client.Timeout = TimeSpan.FromSeconds(60);
                System.String url = "http://localhost:5238";
                url = "http://localhost:5238" + "/";
                url = url + "weatherforecast1";
                System.Text.StringBuilder urlBuilder = new System.Text.StringBuilder();
                urlBuilder.Append(url + "?");
                urlBuilder.Append($"id={id}&");
                urlBuilder.Remove(urlBuilder.Length - 1, 1);
                System.String json = System.Text.Json.JsonSerializer.Serialize("");
                System.Net.Http.StringContent content =
                    new System.Net.Http.StringContent("", System.Text.Encoding.UTF8, "application/json");
                System.Collections.Generic.IDictionary<System.String, System.Object> parameters =
                    new System.Collections.Generic.Dictionary<System.String, System.Object>();
                parameters["client"] = client;
                parameters["url"] = urlBuilder.ToString();
                parameters["data"] = json;
                rpc_service.core.interceptor.impl.RequestInterceptor requestInterceptor =
                    new rpc_service.core.interceptor.impl.RequestInterceptor();
                requestInterceptor.PreInterceptor(parameters);
                try
                {
                    HttpResponseMessage response = client.GetAsync(urlBuilder.ToString()).Result;
                    response.EnsureSuccessStatusCode();
                    System.String responseBody = response.Content.ReadAsStringAsync().Result;
                    requestInterceptor.PostInterceptor(parameters);
                    return responseBody;
                }
                catch (HttpRequestException e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new HttpRequestException(e.Message);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new Exception(e.Message);
                }
            }
        }

        public System.Collections.Generic.List<rpc_service.test.TestModel2> TestRpcMethod2(System.String test)
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {

                client.Timeout = TimeSpan.FromSeconds(60);
                System.String url = "http://localhost:5238";
                url = "http://localhost:5238" + "/";
                url = url + "weatherforecast";
                System.Text.StringBuilder urlBuilder = new System.Text.StringBuilder();
                urlBuilder.Append(url + "?");
                urlBuilder.Append($"test={test}&");
                urlBuilder.Remove(urlBuilder.Length - 1, 1);
                System.String json = System.Text.Json.JsonSerializer.Serialize("");
                System.Net.Http.StringContent content =
                    new System.Net.Http.StringContent("", System.Text.Encoding.UTF8, "application/json");
                System.Collections.Generic.IDictionary<System.String, System.Object> parameters =
                    new System.Collections.Generic.Dictionary<System.String, System.Object>();
                parameters["client"] = client;
                parameters["url"] = urlBuilder.ToString();
                parameters["data"] = json;
                rpc_service.core.interceptor.impl.RequestInterceptor requestInterceptor =
                    new rpc_service.core.interceptor.impl.RequestInterceptor();
                requestInterceptor.PreInterceptor(parameters);
                try
                {
                    HttpResponseMessage response = client.GetAsync(urlBuilder.ToString()).Result;
                    response.EnsureSuccessStatusCode();
                    System.String responseBody = response.Content.ReadAsStringAsync().Result;
                    requestInterceptor.PostInterceptor(parameters);
                    return System.Text.Json.JsonSerializer
                        .Deserialize<System.Collections.Generic.List<rpc_service.test.TestModel2>>(responseBody);
                }
                catch (HttpRequestException e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new HttpRequestException(e.Message);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new Exception(e.Message);
                }
            }
        }

        public System.Collections.Generic.List<rpc_service.test.TestModel2> TestRpcMethod3(
            rpc_service.test.TestModel test)
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {

                client.Timeout = TimeSpan.FromSeconds(60);
                System.String url = "http://localhost:5238";
                url = "http://localhost:5238" + "/";
                url = url + "weatherforecast2";
                System.Text.StringBuilder urlBuilder = new System.Text.StringBuilder();
                urlBuilder.Append(url + "?");
                urlBuilder.Remove(urlBuilder.Length - 1, 1);
                System.String json = System.Text.Json.JsonSerializer.Serialize(test);
                System.Net.Http.StringContent content =
                    new System.Net.Http.StringContent(json, System.Text.Encoding.UTF8, "application/json");
                System.Collections.Generic.IDictionary<System.String, System.Object> parameters =
                    new System.Collections.Generic.Dictionary<System.String, System.Object>();
                parameters["client"] = client;
                parameters["url"] = urlBuilder.ToString();
                parameters["data"] = json;
                rpc_service.core.interceptor.impl.RequestInterceptor requestInterceptor =
                    new rpc_service.core.interceptor.impl.RequestInterceptor();
                requestInterceptor.PreInterceptor(parameters);
                try
                {
                    HttpResponseMessage response = client.PostAsync(urlBuilder.ToString(), content).Result;
                    response.EnsureSuccessStatusCode();
                    System.String responseBody = response.Content.ReadAsStringAsync().Result;
                    requestInterceptor.PostInterceptor(parameters);
                    return System.Text.Json.JsonSerializer
                        .Deserialize<System.Collections.Generic.List<rpc_service.test.TestModel2>>(responseBody);
                }
                catch (HttpRequestException e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new HttpRequestException(e.Message);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new Exception(e.Message);
                }
            }
        }

        public async System.Threading.Tasks.Task<System.Collections.Generic.List<rpc_service.test.TestModel2>>
            TestRpcMethod4(rpc_service.test.TestModel test)
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {

                client.Timeout = TimeSpan.FromSeconds(60);
                System.String url = "http://localhost:5238";
                url = "http://localhost:5238" + "/";
                url = url + "weatherforecast2";
                System.Text.StringBuilder urlBuilder = new System.Text.StringBuilder();
                urlBuilder.Append(url + "?");
                urlBuilder.Remove(urlBuilder.Length - 1, 1);
                System.String json = System.Text.Json.JsonSerializer.Serialize(test);
                System.Net.Http.StringContent content =
                    new System.Net.Http.StringContent(json, System.Text.Encoding.UTF8, "application/json");
                System.Collections.Generic.IDictionary<System.String, System.Object> parameters =
                    new System.Collections.Generic.Dictionary<System.String, System.Object>();
                parameters["client"] = client;
                parameters["url"] = urlBuilder.ToString();
                parameters["data"] = json;
                rpc_service.core.interceptor.impl.RequestInterceptor requestInterceptor =
                    new rpc_service.core.interceptor.impl.RequestInterceptor();
                requestInterceptor.PreInterceptor(parameters);
                try
                {
                    HttpResponseMessage response = await client.PostAsync(urlBuilder.ToString(), content);
                    response.EnsureSuccessStatusCode();
                    System.String responseBody = await response.Content.ReadAsStringAsync();
                    requestInterceptor.PostInterceptor(parameters);
                    return System.Text.Json.JsonSerializer
                        .Deserialize<System.Collections.Generic.List<rpc_service.test.TestModel2>>(responseBody);
                }
                catch (HttpRequestException e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new HttpRequestException(e.Message);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new Exception(e.Message);
                }
            }
        }

        public System.Collections.Generic.Dictionary<System.String,
            System.Collections.Generic.List<rpc_service.test.TestModel2>> TestRpcMethod5(System.String test)
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {

                client.Timeout = TimeSpan.FromSeconds(60);
                System.String url = "http://localhost:5238";
                url = "http://localhost:5238" + "/";
                url = url + "weatherforecast2";
                System.Text.StringBuilder urlBuilder = new System.Text.StringBuilder();
                urlBuilder.Append(url + "?");
                urlBuilder.Append($"test={test}&");
                urlBuilder.Remove(urlBuilder.Length - 1, 1);
                System.String json = System.Text.Json.JsonSerializer.Serialize("");
                System.Net.Http.StringContent content =
                    new System.Net.Http.StringContent("", System.Text.Encoding.UTF8, "application/json");
                System.Collections.Generic.IDictionary<System.String, System.Object> parameters =
                    new System.Collections.Generic.Dictionary<System.String, System.Object>();
                parameters["client"] = client;
                parameters["url"] = urlBuilder.ToString();
                parameters["data"] = json;
                rpc_service.core.interceptor.impl.RequestInterceptor requestInterceptor =
                    new rpc_service.core.interceptor.impl.RequestInterceptor();
                requestInterceptor.PreInterceptor(parameters);
                try
                {
                    HttpResponseMessage response = client.PostAsync(urlBuilder.ToString(), content).Result;
                    response.EnsureSuccessStatusCode();
                    System.String responseBody = response.Content.ReadAsStringAsync().Result;
                    requestInterceptor.PostInterceptor(parameters);
                    return System.Text.Json.JsonSerializer
                        .Deserialize<
                            System.Collections.Generic.Dictionary<System.String,
                                System.Collections.Generic.List<rpc_service.test.TestModel2>>>(responseBody);
                }
                catch (HttpRequestException e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new HttpRequestException(e.Message);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new Exception(e.Message);
                }
            }
        }

    }
}

namespace DynamicProxy
{
    class Test2Proxy : rpc_service.test.Test2
    {
        private Microsoft.Extensions.Logging.ILogger _logger =
            rpc_service.log.Logger.GetLoggerFactory().CreateLogger("Test2Proxy");

        public System.String Test1()
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {

                client.Timeout = TimeSpan.FromSeconds(60);
                System.String url = "http://localhost:5238";
                url = "http://localhost:5238" + "/";
                url = url + "uuid";
                System.Text.StringBuilder urlBuilder = new System.Text.StringBuilder();
                urlBuilder.Append(url + "?");
                urlBuilder.Remove(urlBuilder.Length - 1, 1);
                System.String json = System.Text.Json.JsonSerializer.Serialize("");
                System.Net.Http.StringContent content =
                    new System.Net.Http.StringContent("", System.Text.Encoding.UTF8, "application/json");
                System.Collections.Generic.IDictionary<System.String, System.Object> parameters =
                    new System.Collections.Generic.Dictionary<System.String, System.Object>();
                parameters["client"] = client;
                parameters["url"] = urlBuilder.ToString();
                parameters["data"] = json;
                rpc_service.core.interceptor.impl.RequestInterceptor requestInterceptor =
                    new rpc_service.core.interceptor.impl.RequestInterceptor();
                requestInterceptor.PreInterceptor(parameters);
                try
                {
                    HttpResponseMessage response = client.GetAsync(urlBuilder.ToString()).Result;
                    response.EnsureSuccessStatusCode();
                    System.String responseBody = response.Content.ReadAsStringAsync().Result;
                    requestInterceptor.PostInterceptor(parameters);
                    return responseBody;
                }
                catch (HttpRequestException e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new HttpRequestException(e.Message);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new Exception(e.Message);
                }
            }
        }

    }
}

namespace DynamicProxy
{
    class UUIDApiProxy : rpc_service.external.UUIDApi
    {
        private Microsoft.Extensions.Logging.ILogger _logger =
            rpc_service.log.Logger.GetLoggerFactory().CreateLogger("UUIDApiProxy");

        public System.String Get()
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
            {

                client.Timeout = TimeSpan.FromSeconds(60);
                System.String url = "http://localhost:5012/UUID";
                url = "http://localhost:5012/UUID" + "/";
                url = url + "Get";
                System.Text.StringBuilder urlBuilder = new System.Text.StringBuilder();
                urlBuilder.Append(url + "?");
                urlBuilder.Remove(urlBuilder.Length - 1, 1);
                System.String json = System.Text.Json.JsonSerializer.Serialize("");
                System.Net.Http.StringContent content =
                    new System.Net.Http.StringContent("", System.Text.Encoding.UTF8, "application/json");
                System.Collections.Generic.IDictionary<System.String, System.Object> parameters =
                    new System.Collections.Generic.Dictionary<System.String, System.Object>();
                parameters["client"] = client;
                parameters["url"] = urlBuilder.ToString();
                parameters["data"] = json;
                try
                {
                    HttpResponseMessage response = client.GetAsync(urlBuilder.ToString()).Result;
                    response.EnsureSuccessStatusCode();
                    System.String responseBody = response.Content.ReadAsStringAsync().Result;
                    return responseBody;
                }
                catch (HttpRequestException e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new HttpRequestException(e.Message);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Request error: {e.Message}");
                    throw new Exception(e.Message);
                }
            }
        }

    }
}
   